package com.boot.app.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.boot.app.system.domain.SystemCode;
import com.boot.app.system.domain.SystemDict;
import com.boot.app.system.mapper.SystemDictMapper;
import com.boot.app.system.service.ISystemDictService;
import com.boot.app.system.service.ISystemCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class SystemDictServiceImpl extends ServiceImpl<SystemDictMapper, SystemDict> implements ISystemDictService {

    private final SystemDictMapper mapper;

    private final ISystemCodeService codeService;


    @Autowired
    public SystemDictServiceImpl(
        SystemDictMapper mapper,
        ISystemCodeService codeService
    ){
        this.mapper = mapper;
        this.codeService = codeService;
    }

    @Override
    @Transactional
    public void removeById(Long id) {
        mapper.deleteById(id);

        LambdaQueryWrapper<SystemCode> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SystemCode::getDictId, id);
        codeService.remove(wrapper);
    }
}
